package com.igd.security;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import com.igd.pojo.vo.ComboxData;
import com.igd.utils.CommonUtil;
import com.igd.utils.DateUtil;

/**
 * @version 1.0
 * 
 * @author QIAOYU
 * 
 * @date 2013-6-20
 * 
 * @description 平台用户信息数据类
 */

public class User {
	
	private String listKey = "user.status.list";
	
	private String valKey = "user.status";
	
	/**用户编号*/
	private String userId;

	/**用户登录名称*/
	private String userName;

	/**用户登录密码*/
	private String userPwd;

	/**用户状态*/
	private String userStatus;

	/**用户创建时间*/
	private String userCreateTime;

	/**用户真实姓名*/
	private String userRealName;

	/**用户固定电话*/
	private String userPhone;

	/**用户移动电话*/
	private String userMobile;

	/**用户分机号码*/
	private String userSubPhone;

	/**用户最后登录时间*/
	private String userLastLoginTime;

	/**用户地址*/
	private String userAddress;
	
	/**用户对应角色集合*/
	private List<Roles> userRoles;
	
	/**用户邮箱*/
	private String userEmail;
	
	private HashMap<Resources,List<Resources>> userAllRes = null;
	
	private Date userCreateTimeFormat;
	
	private Date userLastLoginTimeFormat;
	
	private List<ComboxData> userStatusMapping = CommonUtil.toComboxList(listKey,valKey);
	
	/** 根据用户角色对应的资源与初始化的根资源创建树形数据菜单 */
	public void buildMenuTreeMap(List<Resources> rootMenu){
		
		if(null != rootMenu && rootMenu.size() > 0){
			
			List<Resources> roleAllRes = new ArrayList<Resources>();
			
			for(Roles role : this.getUserRoles()){
				
				roleAllRes.addAll(role.getRoleResources());

			}
			
			HashMap<Resources,List<Resources>> mapRes = new HashMap<Resources,List<Resources>>();
			
			for(Resources rootRes : rootMenu){
				
				ArrayList<Resources> res = new ArrayList<Resources>();
				
				for(Resources mRes : roleAllRes){
					
					if(rootRes.getResNodeNum().equals(mRes.getResNodeNum().substring(0,2))){
						
						res.add(mRes);

					}
				}
				
				mapRes.put(rootRes, res);
			}
			
			this.setUserAllRes(mapRes);
			
		}
	}
	
	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getUserPwd() {
		return userPwd;
	}

	public void setUserPwd(String userPwd) {
		this.userPwd = userPwd;
	}

	public String getUserStatus() {
		return userStatus;
	}

	public void setUserStatus(String userStatus) {
		this.userStatus = userStatus;
	}

	public String getUserCreateTime() {
		return userCreateTime;
	}

	public void setUserCreateTime(String userCreateTime) {
		
		this.userCreateTime = userCreateTime;
		
		this.userCreateTimeFormat = DateUtil.formateStringToDate(this.userCreateTime,DateUtil.FORMAT_TO_14);
	}

	public String getUserRealName() {
		return userRealName;
	}

	public void setUserRealName(String userRealName) {
		this.userRealName = userRealName;
	}

	public String getUserPhone() {
		return userPhone;
	}

	public void setUserPhone(String userPhone) {
		this.userPhone = userPhone;
	}

	public String getUserMobile() {
		return userMobile;
	}

	public void setUserMobile(String userMobile) {
		this.userMobile = userMobile;
	}

	public String getUserSubPhone() {
		return userSubPhone;
	}

	public void setUserSubPhone(String userSubPhone) {
		this.userSubPhone = userSubPhone;
	}

	public String getUserLastLoginTime() {
		return userLastLoginTime;
	}

	public void setUserLastLoginTime(String userLastLoginTime) {
		
		this.userLastLoginTime = userLastLoginTime;
		
		this.userLastLoginTimeFormat = DateUtil.formateStringToDate(this.userLastLoginTime,DateUtil.FORMAT_TO_14);
	}

	public String getUserAddress() {
		return userAddress;
	}

	public void setUserAddress(String userAddress) {
		this.userAddress = userAddress;
	}

	public List<Roles> getUserRoles() {
		return userRoles;
	}

	public void setUserRoles(List<Roles> userRoles) {
		this.userRoles = userRoles;
	}

	public HashMap<Resources, List<Resources>> getUserAllRes() {
		return userAllRes;
	}

	public void setUserAllRes(HashMap<Resources, List<Resources>> userAllRes) {
		this.userAllRes = userAllRes;
	}

	public Date getUserCreateTimeFormat() {
		return userCreateTimeFormat;
	}

	public void setUserCreateTimeFormat(Date userCreateTimeFormat) {
		this.userCreateTimeFormat = userCreateTimeFormat;
	}

	public Date getUserLastLoginTimeFormat() {
		return userLastLoginTimeFormat;
	}

	public void setUserLastLoginTimeFormat(Date userLastLoginTimeFormat) {
		this.userLastLoginTimeFormat = userLastLoginTimeFormat;
	}

	public String getUserEmail() {
		return userEmail;
	}

	public void setUserEmail(String userEmail) {
		this.userEmail = userEmail;
	}

	public List<ComboxData> getUserStatusMapping() {
		return userStatusMapping;
	}

	public void setUserStatusMapping(List<ComboxData> userStatusMapping) {
		this.userStatusMapping = userStatusMapping;
	}
}
